<?PHP
if (!session_start()) { session_start(); };
/*if (!isset($_SESSION['lgnapproved'])) {
	die(header('Location: login.php'));
}*/
include("functions.php");
include("cnnxn.php");
connect();

$SQLd='SELECT * FROM av_divisions WHERE id='.$_GET['did'].';';
$sendit_d=mysqli_query($db,$SQLd) or die(mysqli_error($db));
$RSd=mysqli_fetch_object($sendit_d);

//print '<p>'.$RSd->divisionname.', '.$RSd->teamsize.'</p>';

if (isset($_POST['submit'])) {
	$eventID=$_GET['eid'];
	$divisionID=$_GET['did'];
	$si=0;
	$SQLplayers='';
	foreach ($_POST as $key=>$value) {
		if ($key!='submit') {
			$si++;
			$tempArray=array(explode("_",$key));
			if ($tempArray[0][2]!='finishposition') {
				$SQLplayers=$SQLplayers.'"'.$value.'",';
			} else {
				if ($RSd->teamsize==2) {
					$SQLlr='INSERT INTO av_eventplayers (eventid,divisionid,player01,player02,player03,player04,finishposition) VALUES ('.$eventID.','.$divisionID.','.$SQLplayers.'"","",'.$value.');';
				} else {
					$SQLlr='INSERT INTO av_eventplayers (eventid,divisionid,player01,player02,player03,player04,finishposition) VALUES ('.$eventID.','.$divisionID.','.$SQLplayers.$value.');';
				}
				$sendlr=mysqli_query($db,$SQLlr) or die(mysqli_error($db));
				$SQLplayers='';
			}
		}
	}
	mysqli_close($db);
	die(header("Location: av_eventresults.php?eid=".$_GET['eid']));
}

?>
